<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //promnise 串联多个同步或异步操作

        new Promise((resolve, reject) => {
            setTimeout(() => {

                console.log("执行异步任务1")
                resolve(1)
               
            }, 1000)
        }).then(
            value => {
                console.log("异步任务1的结果", value)
                console.log("执行同步任务2")
                return 2
            }
        ).then(
            value => {
                console.log("同步任务2的结果", value)
                return new Promise((resolve, reject) => {

                    console.log("执行异步任务3")
                    resolve(3)
                   
                })
            }
        ).then(
            value => {
                console.log("异步任务3的结果", value)
            }
        )

        //如果中间有异步操作的话，要将异步操作包装在一个新的promise中，
        //也印证了之前说的，promise是用来封装异步操作的
    </script>
</body>

</html>